class Solution {
public:
    string reverseOnlyLetters(string s) {
        int left = 0, right = s.size() - 1;
        while (true)
        {
            while (left < right && !isalpha(s[left])) left++;
            while (right > left && !isalpha(s[right])) right--;
            if (left > right) break;
            swap(s[left], s[right]);
            left++, right--;
        }
        return s;
    }
};

class Solution {
public:
    string minWindow(string s, string t) {
        int hash1[128] = { 0 };
        int hash2[128] = { 0 };
        int kinds = 0;
        int minLen = INT_MAX;
        int begin = -1;
        for (auto& ch : t) if (hash1[ch]++ == 0) kinds++;
        for (int left = 0, right = 0, cnt = 0; right < s.size(); right++)
        {
            char in = s[right];
            if (++hash2[in] == hash1[in]) cnt++;
            while (cnt == kinds)
            {
                if (right - left + 1 < minLen)
                {
                    begin = left;
                    minLen = right - left + 1;
                }
                char out = s[left++];
                if (hash2[out]-- == hash1[out]) cnt--;
            }
        }
        if (begin == -1) return "";
        else return s.substr(begin, minLen);
    }
};